//
//  ImagePreView.m
//  ShouKuang
//
//  Created by CodeYY on 2019/6/20.
//  Copyright © 2019 CodeYY. All rights reserved.
//

#import "ImagePreView.h"
@interface ImagePreView()
@property(nonatomic, copy)NSString *imgName;
@property(nonatomic, copy)NSString *titleStr;

@end
@implementation ImagePreView

+(void)imagePreView:(NSString *)imgName titleStr:(NSString *)titleStr
{
    ImagePreView *preView = [ImagePreView new];
    preView.imgName = imgName;
    preView.titleStr = titleStr;
    [preView initContentView];
    preView.frame = CGRectMake(0, 0, Main_Screen_Width, Main_Screen_Height);
    [[UIApplication sharedApplication].windows.firstObject addSubview:preView];
}

-(void)initContentView
{
    __weak typeof(self) weakSelf = self;
    UIButton *shadowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:shadowBtn];
    shadowBtn.alpha = 0.3;
    [shadowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    shadowBtn.backgroundColor = [UIColor blackColor];
    [[shadowBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x) {
        [weakSelf removeFromSuperview];
    }];
    
    UIButton *btn = [UIButton buttonWithType: UIButtonTypeCustom];
    [self addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(18);
        make.top.offset(70);
    }];
    [btn setImage:[UIImage imageNamed:@"nav_back_white"] forState:UIControlStateNormal];
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(id x) {
        [weakSelf removeFromSuperview];
        
    }];
    
    UIImageView *imgView =[UIImageView new];
    [self addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.offset(0);
            make.size.mas_equalTo(CGSizeMake(320, 220));
//        //设置宽高比例为7：1
//        make.width.mas_equalTo(imgView.mas_height).multipliedBy(7);
        
        }];
    imgView.image = [UIImage imageNamed:_imgName];
    UILabel *lab ;
    if (_titleStr) {
        lab = [UILabel new];
        [self addSubview:lab];
        lab.textColor = [UIColor whiteColor];
        lab.numberOfLines = 0;
        lab.textAlignment = NSTextAlignmentCenter;
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.offset(-30);
            make.width.mas_equalTo(250);
            make.centerX.offset(0);
            make.height.mas_lessThanOrEqualTo(80);
        }];
        lab.text = _titleStr;
    }
    
  
    
}


@end
